package com.sk.ccflower.lib.commonUtils;

import java.io.File;
import java.io.FileInputStream;

import com.sk.ccflower.server.lib.sysUtils.Environment;

public class PhotoUtil {
	
	public static byte[] getDefaultPhoto( String email, String type ) throws Exception {
		byte[] retBytes = null;
		
		try {
			String path = Environment.getDataProfileDir();
			path += File.separator + email;
			path += File.separator + type + ".jpg";
			
			File file = new File( path );
			FileInputStream fis = new FileInputStream( file );
			retBytes = new byte[(int) file.length()];
			fis.read( retBytes );
			fis.close();
		} catch ( Exception e ) {
			throw e;
		}
		
		return retBytes;
	}
	
	public static byte[] getPhoto( String email, String name ) throws Exception {
		byte[] retBytes = null;
		
		try {
			String path = Environment.getDataProfileDir();
			path += File.separator + email;
			path += File.separator + name + ".jpg";
			
			File file = new File( path );
			if ( file.exists() ) {
				FileInputStream fis = new FileInputStream( file );
				retBytes = new byte[(int) file.length()];
				fis.read( retBytes );
				fis.close();
			}
		} catch ( Exception e ) {
			throw e;
		}
		
		return retBytes;
	}
	
}
